' ======================================================================
' 执行所有 case
' ======================================================================
Private Sub test_All_Case()
    ' 切片初始化 --- 全手动指定需要的行列索引，并执行基础测试
    test_init_by_rowIndexes_colIndexes
    ' 切片初始化 --- 指定需要的行列范围
    test_init_by_index_range
    ' 切片初始化 --- 创建包含全列的空行引用对象
    test_init_by_InitEmptyRowRef
    ' 测试: 添加空行引用
    test_appendEmptyRow
    ' 测试: 拷贝行
    test_copyAndAppendRow
    ' 测试: 添加一整行数据
    test_appendRowByColDatas
    ' 测试: 添加一整行数据
    test_appendRowByColDataArray
    ' 测试: 删除指定索引的行
    test_delRow
    ' 测试: 删除指定索引的行
    test_delRowByIndexArray
    ' 测试: 删除指定索引的行
    test_deepDelRow
    ' 测试: 删除指定索引的行
    test_deepDelRowByIndexArray
    ' 测试: 检查是否存在指定的列
    test_hasColumn
    ' 测试: 检查是否存在指定的列
    test_deepHasColumn
    ' 测试: 将列索引转换成列名
    test_colIndexToName
    ' 测试: 将列名转换成列索引
    test_colNameToIndex
    ' 测试: 获取列对象
    test_getCol
    ' 测试: 删除指定索引的列
    test_delCol
    ' 测试: 删除指定索引的列
    test_delColByIndexArray
    ' 测试: 删除指定索引的列
    test_deepDelCol
    ' 测试: 删除指定索引的列
    test_deepDelColByIndexArray
    ' 测试: 增加新的列
    test_addCol
    ' 测试: 获取指定行的描述器
    test_getRowDescriptor
    ' 测试: 获取指定行列确定的槽位的描述器
    test_getDataDescriptor
    ' 测试: 读取数据
    test_getDataByColIndex
    ' 测试: 读取数据
    test_getDataByColName
    ' 测试: 写入数据
    test_setDataByColIndex
    ' 测试: 写入数据
    test_setDataByColName
    ' 测试: 创建多级切片
    test_slice

    ' ==================================================
    ' 以下方法无法断言，只能手动检查
    ' ==================================================
    ' 测试: 将 DataFrame 中的内容输出到控制台
    ' test_printToConsole
    ' 测试: 将 DataFrame 中的内容输出到指定 sheet 中
    ' test_printToWorksheet
End Sub

' ======================================================================
' 通用方法
' ======================================================================
' 生成指定大小的 DataFrame
Private Function getStringDF(ByRef rsize As Long, ByRef csize As Integer) As IDataFrame
    Dim df As IDataFrame
    Dim realDF As DataFrame
    Set realDF = New DataFrame
    realDF.Init colCount:=csize, initRowSize:=rsize

    Set df = realDF
    df.appendEmptyRow rsize

    Dim ri As Long
    Dim ci As Integer
    For ri = 0 To rsize - 1
        For ci = 0 To csize - 1
            df.setDataByColIndex ri, ci, "c" & ri & ci
        Next
    Next

    Set getStringDF = df
End Function

' ======================================================================
' 测试 case
' ======================================================================
' 切片初始化 --- 全手动指定需要的行列索引，并执行基础测试
Private Sub test_init_by_rowIndexes_colIndexes()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4, 3, 2, 1)
    colIndexes = Array(1, 3, 5)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 检查结果
    ' 4.1 检查切片中的数据数量
    Debug.Assert dfSlice.Size = 5
    Debug.Assert dfSlice.ColumnCount = 3

    ' 4.2 检查切片中的数据
    Dim i As Long
    Dim j As Integer
    For i = 0 To 4
        For j = 0 To 2
            Debug.Assert dfSlice.getDataByColIndex(i, j) = "c" & rowIndexes(i) & colIndexes(j)
        Next
    Next

    ' 4.3 检查列名
    Dim sliceColNames As Collection
    Set sliceColNames = dfSlice.ColumnNames
    Debug.Assert sliceColNames.Count = 3
    Debug.Assert sliceColNames.Item(1) = "1"
    Debug.Assert sliceColNames.Item(2) = "3"
    Debug.Assert sliceColNames.Item(3) = "5"

    ' 4.4 手动设置 ID，并检查
    dfSlice.ID = "xyz"
    Debug.Assert dfSlice.ID = "xyz"

    ' 4.5 获取一个列对象
    Dim realSlice As DataFrameSlice
    Set realSlice = dfSlice
    Dim colSeries As IDFSeries
    Set colSeries = realSlice.unsafeGetDelegatedCol(1)
    Debug.Assert colSeries.Size = 20
    Debug.Assert colSeries.getData(0) = "c01"
    Debug.Assert colSeries.getData(1) = "c11"
    Debug.Assert colSeries.getData(2) = "c21"
    Debug.Assert colSeries.getData(3) = "c31"
    Debug.Assert colSeries.getData(4) = "c41"
    Debug.Assert colSeries.getData(5) = "c51"
End Sub

' 切片初始化 --- 指定需要的行列范围
Private Sub test_init_by_index_range()
    ' 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 创建切片
    ' 切片的索引:
    ' 1 3 5 7 9
    ' 1 3 5 7 9
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice( _
        rowStart := 1, _
        rowStop := 10, _
        rowStep := 2, _
        colStart := 1, _
        colStop := 11, _
        colStep := 2 _
    )

    ' 检查结果
    Debug.Assert dfSlice.Size = 5
    Debug.Assert dfSlice.ColumnCount = 5

    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(1, 3, 5, 7, 9)
    colIndexes = Array(1, 3, 5, 7, 9)

    Dim i As Long
    Dim j As Integer
    For i = 0 To 4
        For j = 0 To 4
            Debug.Assert dfSlice.getDataByColIndex(i, j) = "c" & rowIndexes(i) & colIndexes(j)
        Next
    Next
End Sub

' 切片初始化 --- 创建包含全列的空行引用对象
Private Sub test_init_by_InitEmptyRowRef()
    ' 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 创建切片
    Dim dfSlice As DataFrameSlice
    Set dfSlice = New DataFrameSlice
    dfSlice.InitEmptyRowRef df

    Dim slice As IDataFrame
    Set slice = dfSlice

    ' 检查结果
    Debug.Assert slice.Size = 0
    Debug.Assert slice.ColumnCount = 20

    ' 添加两行引用
    dfSlice.appendRef 2
    Debug.Assert slice.Size = 1
    Debug.Assert slice.Size = 1

    Dim i As Long
    Dim ci As Integer
    For ci = 0 To 20 - 1
        Debug.Assert slice.getDataByColIndex(0, ci) = "c2" & ci
    Next

    dfSlice.appendRef 10
    Debug.Assert slice.Size = 2
    Debug.Assert slice.Size = 2
    For ci = 0 To 20 - 1
        Debug.Assert slice.getDataByColIndex(1, ci) = "c10" & ci
    Next

End Sub

' 测试: 添加空行引用
Private Sub test_appendEmptyRow()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4, 3, 2, 1)
    colIndexes = Array(1, 3, 5)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 添加空行
    Debug.Assert dfSlice.Size = 5
    Debug.Assert df.Size = 20
    dfSlice.appendEmptyRow(2)
    Debug.Assert dfSlice.Size = 7
    Debug.Assert df.Size = 22
End Sub

' 测试: 拷贝行
Private Sub test_copyAndAppendRow()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4, 3, 2, 1)
    colIndexes = Array(1, 3, 5)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 拷贝引用行
    Debug.Assert dfSlice.Size = 5
    Debug.Assert df.Size = 20

    dfSlice.copyAndAppendRow 1

    Debug.Assert dfSlice.Size = 6
    Debug.Assert df.Size = 21

    Debug.Assert dfSlice.getDataByColIndex(5, 0) = "c41"
    Debug.Assert dfSlice.getDataByColIndex(5, 1) = "c43"
    Debug.Assert dfSlice.getDataByColIndex(5, 2) = "c45"

    Debug.Assert df.getDataByColIndex(20, 0) = "c40"
    Debug.Assert df.getDataByColIndex(20, 1) = "c41"
    Debug.Assert df.getDataByColIndex(20, 2) = "c42"
    Debug.Assert df.getDataByColIndex(20, 3) = "c43"
End Sub

' 测试: 添加一整行数据
Private Sub test_appendRowByColDatas()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4, 3, 2, 1)
    colIndexes = Array(1, 3, 5, 7)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 插入数据
    Debug.Assert df.Size = 20
    Debug.Assert dfSlice.Size = 5

    ' 插入空行不会生效
    dfSlice.appendRowByColDatas
    ' 插入一行数据: 数据数量 = 列数
    dfSlice.appendRowByColDatas "d00", "d01", "d02", "d03"
    ' 插入一行数据: 数据数量 < 列数
    dfSlice.appendRowByColDatas "d10", "d11"
    ' 插入一行数据: 数据数量 > 列数
    dfSlice.appendRowByColDatas "d20", "d21", "d22", "d23", "d24", "d25"

    ' 检查结果
    Debug.Assert df.Size = 23
    Debug.Assert dfSlice.Size = 8

    Debug.Assert dfSlice.getDataByColIndex(5, 0) = "d00"
    Debug.Assert dfSlice.getDataByColIndex(5, 1) = "d01"
    Debug.Assert dfSlice.getDataByColIndex(5, 2) = "d02"
    Debug.Assert dfSlice.getDataByColIndex(5, 3) = "d03"

    Debug.Assert dfSlice.getDataByColIndex(6, 0) = "d10"
    Debug.Assert dfSlice.getDataByColIndex(6, 1) = "d11"
    Debug.Assert dfSlice.getDataByColIndex(6, 2) = Empty
    Debug.Assert dfSlice.getDataByColIndex(6, 3) = Empty

    Debug.Assert dfSlice.getDataByColIndex(7, 0) = "d20"
    Debug.Assert dfSlice.getDataByColIndex(7, 1) = "d21"
    Debug.Assert dfSlice.getDataByColIndex(7, 2) = "d22"
    Debug.Assert dfSlice.getDataByColIndex(7, 3) = "d23"

    Debug.Assert df.getDataByColIndex(20, 0) = Empty
    Debug.Assert df.getDataByColIndex(20, 1) = "d00"
    Debug.Assert df.getDataByColIndex(20, 3) = "d01"
    Debug.Assert df.getDataByColIndex(20, 5) = "d02"
    Debug.Assert df.getDataByColIndex(20, 7) = "d03"

    Debug.Assert df.getDataByColIndex(21, 0) = Empty
    Debug.Assert df.getDataByColIndex(21, 1) = "d10"
    Debug.Assert df.getDataByColIndex(21, 3) = "d11"
    Debug.Assert df.getDataByColIndex(21, 5) = Empty
    Debug.Assert df.getDataByColIndex(21, 7) = Empty

    Debug.Assert df.getDataByColIndex(22, 0) = Empty
    Debug.Assert df.getDataByColIndex(22, 1) = "d20"
    Debug.Assert df.getDataByColIndex(22, 3) = "d21"
    Debug.Assert df.getDataByColIndex(22, 5) = "d22"
    Debug.Assert df.getDataByColIndex(22, 7) = "d23"
End Sub

' 测试: 添加一整行数据
Private Sub test_appendRowByColDataArray()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4, 3, 2, 1)
    colIndexes = Array(1, 3, 5, 7)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 插入数据
    Debug.Assert df.Size = 20
    Debug.Assert dfSlice.Size = 5

    ' 插入空行不会生效
    dfSlice.appendRowByColDataArray Array()
    ' 插入一行数据: 数据数量 = 列数
    dfSlice.appendRowByColDataArray Array("d00", "d01", "d02", "d03")
    ' 插入一行数据: 数据数量 < 列数
    dfSlice.appendRowByColDataArray Array("d10", "d11")
    ' 插入一行数据: 数据数量 > 列数
    dfSlice.appendRowByColDataArray Array("d20", "d21", "d22", "d23", "d24", "d25")

    ' 检查结果
    Debug.Assert df.Size = 23
    Debug.Assert dfSlice.Size = 8

    Debug.Assert dfSlice.getDataByColIndex(5, 0) = "d00"
    Debug.Assert dfSlice.getDataByColIndex(5, 1) = "d01"
    Debug.Assert dfSlice.getDataByColIndex(5, 2) = "d02"
    Debug.Assert dfSlice.getDataByColIndex(5, 3) = "d03"

    Debug.Assert dfSlice.getDataByColIndex(6, 0) = "d10"
    Debug.Assert dfSlice.getDataByColIndex(6, 1) = "d11"
    Debug.Assert dfSlice.getDataByColIndex(6, 2) = Empty
    Debug.Assert dfSlice.getDataByColIndex(6, 3) = Empty

    Debug.Assert dfSlice.getDataByColIndex(7, 0) = "d20"
    Debug.Assert dfSlice.getDataByColIndex(7, 1) = "d21"
    Debug.Assert dfSlice.getDataByColIndex(7, 2) = "d22"
    Debug.Assert dfSlice.getDataByColIndex(7, 3) = "d23"

    Debug.Assert df.getDataByColIndex(20, 0) = Empty
    Debug.Assert df.getDataByColIndex(20, 1) = "d00"
    Debug.Assert df.getDataByColIndex(20, 3) = "d01"
    Debug.Assert df.getDataByColIndex(20, 5) = "d02"
    Debug.Assert df.getDataByColIndex(20, 7) = "d03"

    Debug.Assert df.getDataByColIndex(21, 0) = Empty
    Debug.Assert df.getDataByColIndex(21, 1) = "d10"
    Debug.Assert df.getDataByColIndex(21, 3) = "d11"
    Debug.Assert df.getDataByColIndex(21, 5) = Empty
    Debug.Assert df.getDataByColIndex(21, 7) = Empty

    Debug.Assert df.getDataByColIndex(22, 0) = Empty
    Debug.Assert df.getDataByColIndex(22, 1) = "d20"
    Debug.Assert df.getDataByColIndex(22, 3) = "d21"
    Debug.Assert df.getDataByColIndex(22, 5) = "d22"
    Debug.Assert df.getDataByColIndex(22, 7) = "d23"
End Sub

' 测试: 删除指定索引的行
Private Sub test_delRow()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4, 3, 2, 1)
    colIndexes = Array(1, 3, 5)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 删除引用行
    Debug.Assert dfSlice.Size = 5
    Debug.Assert df.Size = 20

    dfSlice.delRow 1, 2

    Debug.Assert dfSlice.Size = 3
    Debug.Assert df.Size = 20

    Debug.Assert dfSlice.getDataByColIndex(0, 0) = "c51"
    Debug.Assert dfSlice.getDataByColIndex(0, 1) = "c53"
    Debug.Assert dfSlice.getDataByColIndex(0, 2) = "c55"

    Debug.Assert dfSlice.getDataByColIndex(1, 0) = "c21"
    Debug.Assert dfSlice.getDataByColIndex(1, 1) = "c23"
    Debug.Assert dfSlice.getDataByColIndex(1, 2) = "c25"

    Debug.Assert dfSlice.getDataByColIndex(2, 0) = "c11"
    Debug.Assert dfSlice.getDataByColIndex(2, 1) = "c13"
    Debug.Assert dfSlice.getDataByColIndex(2, 2) = "c15"
End Sub

' 测试: 删除指定索引的行
Private Sub test_delRowByIndexArray()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4, 3, 2, 1)
    colIndexes = Array(1, 3, 5)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 删除引用行
    Debug.Assert dfSlice.Size = 5
    Debug.Assert df.Size = 20

    dfSlice.delRowByIndexArray Array(1, 2)

    Debug.Assert dfSlice.Size = 3
    Debug.Assert df.Size = 20

    Debug.Assert dfSlice.getDataByColIndex(0, 0) = "c51"
    Debug.Assert dfSlice.getDataByColIndex(0, 1) = "c53"
    Debug.Assert dfSlice.getDataByColIndex(0, 2) = "c55"

    Debug.Assert dfSlice.getDataByColIndex(1, 0) = "c21"
    Debug.Assert dfSlice.getDataByColIndex(1, 1) = "c23"
    Debug.Assert dfSlice.getDataByColIndex(1, 2) = "c25"

    Debug.Assert dfSlice.getDataByColIndex(2, 0) = "c11"
    Debug.Assert dfSlice.getDataByColIndex(2, 1) = "c13"
    Debug.Assert dfSlice.getDataByColIndex(2, 2) = "c15"
End Sub

' 测试: 删除指定索引的行
Private Sub test_deepDelRow()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4, 3, 2, 1)
    colIndexes = Array(1, 3, 5)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 删除引用行
    Debug.Assert dfSlice.Size = 5
    Debug.Assert df.Size = 20

    dfSlice.deepDelRow 1, 2

    Debug.Assert dfSlice.Size = 3
    Debug.Assert df.Size = 18

    ' 因为删除导致了引用数据发生了变化
    Debug.Assert dfSlice.getDataByColIndex(0, 0) = "c71"
    Debug.Assert dfSlice.getDataByColIndex(0, 1) = "c73"
    Debug.Assert dfSlice.getDataByColIndex(0, 2) = "c75"

    Debug.Assert dfSlice.getDataByColIndex(1, 0) = "c21"
    Debug.Assert dfSlice.getDataByColIndex(1, 1) = "c23"
    Debug.Assert dfSlice.getDataByColIndex(1, 2) = "c25"

    Debug.Assert dfSlice.getDataByColIndex(2, 0) = "c11"
    Debug.Assert dfSlice.getDataByColIndex(2, 1) = "c13"
    Debug.Assert dfSlice.getDataByColIndex(2, 2) = "c15"
End Sub

' 测试: 删除指定索引的行
Private Sub test_deepDelRowByIndexArray()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4, 3, 2, 1)
    colIndexes = Array(1, 3, 5)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 删除引用行
    Debug.Assert dfSlice.Size = 5
    Debug.Assert df.Size = 20

    dfSlice.deepDelRowByIndexArray Array(1, 2)

    Debug.Assert dfSlice.Size = 3
    Debug.Assert df.Size = 18

    ' 因为删除导致了引用数据发生了变化
    Debug.Assert dfSlice.getDataByColIndex(0, 0) = "c71"
    Debug.Assert dfSlice.getDataByColIndex(0, 1) = "c73"
    Debug.Assert dfSlice.getDataByColIndex(0, 2) = "c75"

    Debug.Assert dfSlice.getDataByColIndex(1, 0) = "c21"
    Debug.Assert dfSlice.getDataByColIndex(1, 1) = "c23"
    Debug.Assert dfSlice.getDataByColIndex(1, 2) = "c25"

    Debug.Assert dfSlice.getDataByColIndex(2, 0) = "c11"
    Debug.Assert dfSlice.getDataByColIndex(2, 1) = "c13"
    Debug.Assert dfSlice.getDataByColIndex(2, 2) = "c15"
End Sub

' 测试: 检查是否存在指定的列
Private Sub test_hasColumn()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4, 3, 2, 1)
    colIndexes = Array(1, 3, 5)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 检查是否存在指定的列
    Debug.Assert dfSlice.hasColumn(0)
    Debug.Assert dfSlice.hasColumn(1)
    Debug.Assert dfSlice.hasColumn(2)
    Debug.Assert dfSlice.hasColumn(3) = False
End Sub

' 测试: 检查是否存在指定的列
Private Sub test_deepHasColumn()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4, 3, 2, 1)
    colIndexes = Array(1, 3, 5)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 检查是否存在指定的列
    Debug.Assert dfSlice.deepHasColumn(0)
    Debug.Assert dfSlice.deepHasColumn(1)
    Debug.Assert dfSlice.deepHasColumn(19)
    Debug.Assert dfSlice.deepHasColumn(20) = False
End Sub

' 测试: 将列索引转换成列名
Private Sub test_colIndexToName()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4, 3, 2, 1)
    colIndexes = Array(1, 3, 5)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 检查是否存在指定的列
    Debug.Assert dfSlice.colIndexToName(0) = "1"
    Debug.Assert dfSlice.colIndexToName(1) = "3"
    Debug.Assert dfSlice.colIndexToName(2) = "5"
End Sub

' 测试: 将列名转换成列索引
Private Sub test_colNameToIndex()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4, 3, 2, 1)
    colIndexes = Array(1, 3, 5)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 检查是否存在指定的列
    Debug.Assert dfSlice.colNameToIndex("1") = 0
    Debug.Assert dfSlice.colNameToIndex("3") = 1
    Debug.Assert dfSlice.colNameToIndex("5") = 2
End Sub

' 测试: 获取列对象
Private Sub test_getCol()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4, 3, 2, 1)
    colIndexes = Array(1, 3, 5)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 获取列对象
    Dim col As IDFSeries
    Set col = dfSlice.getCol(1)
    Debug.Assert col.Size = 5
    Debug.Assert col.getData(0) = "c53"
    Debug.Assert col.getData(1) = "c43"
    Debug.Assert col.getData(2) = "c33"
    Debug.Assert col.getData(3) = "c23"
    Debug.Assert col.getData(4) = "c13"
End Sub

' 测试: 删除指定索引的列
Private Sub test_delCol()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4)
    colIndexes = Array(1, 3, 5, 7)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 删除指定索引的列
    Debug.Assert dfSlice.ColumnCount = 4
    Debug.Assert df.ColumnCount = 20

    dfSlice.delCol 1, 2

    Debug.Assert dfSlice.ColumnCount = 2
    Debug.Assert df.ColumnCount = 20

    Debug.Assert dfSlice.getDataByColIndex(0, 0) = "c51"
    Debug.Assert dfSlice.getDataByColIndex(0, 1) = "c57"

    Debug.Assert dfSlice.getDataByColIndex(1, 0) = "c41"
    Debug.Assert dfSlice.getDataByColIndex(1, 1) = "c47"
End Sub

' 测试: 删除指定索引的列
Private Sub test_delColByIndexArray()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4)
    colIndexes = Array(1, 3, 5, 7)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 删除指定索引的列
    Debug.Assert dfSlice.ColumnCount = 4
    Debug.Assert df.ColumnCount = 20

    dfSlice.delColByIndexArray Array(1, 2)

    Debug.Assert dfSlice.ColumnCount = 2
    Debug.Assert df.ColumnCount = 20

    Debug.Assert dfSlice.getDataByColIndex(0, 0) = "c51"
    Debug.Assert dfSlice.getDataByColIndex(0, 1) = "c57"

    Debug.Assert dfSlice.getDataByColIndex(1, 0) = "c41"
    Debug.Assert dfSlice.getDataByColIndex(1, 1) = "c47"
End Sub

' 测试: 删除指定索引的列
Private Sub test_deepDelCol()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4)
    colIndexes = Array(1, 3, 5, 7)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 删除指定索引的列
    Debug.Assert dfSlice.ColumnCount = 4
    Debug.Assert df.ColumnCount = 20

    dfSlice.deepDelCol 1, 2

    Debug.Assert dfSlice.ColumnCount = 2
    Debug.Assert df.ColumnCount = 18

    Debug.Assert dfSlice.getDataByColIndex(0, 0) = "c51"
    Debug.Assert dfSlice.getDataByColIndex(0, 1) = "c57"

    Debug.Assert dfSlice.getDataByColIndex(1, 0) = "c41"
    Debug.Assert dfSlice.getDataByColIndex(1, 1) = "c47"
End Sub

' 测试: 删除指定索引的列
Private Sub test_deepDelColByIndexArray()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4)
    colIndexes = Array(1, 3, 5, 7)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 删除指定索引的列
    Debug.Assert dfSlice.ColumnCount = 4
    Debug.Assert df.ColumnCount = 20

    dfSlice.deepDelColByIndexArray Array(1, 2)

    Debug.Assert dfSlice.ColumnCount = 2
    Debug.Assert df.ColumnCount = 18

    Debug.Assert dfSlice.getDataByColIndex(0, 0) = "c51"
    Debug.Assert dfSlice.getDataByColIndex(0, 1) = "c57"

    Debug.Assert dfSlice.getDataByColIndex(1, 0) = "c41"
    Debug.Assert dfSlice.getDataByColIndex(1, 1) = "c47"
End Sub

' 测试: 增加新的列
Private Sub test_addCol()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4)
    colIndexes = Array(1, 3)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 删除指定索引的列
    Debug.Assert dfSlice.ColumnCount = 2
    Debug.Assert df.ColumnCount = 20

    dfSlice.addCol "colX", DF_DataType.DF_STRING

    Debug.Assert dfSlice.ColumnCount = 3
    Debug.Assert df.ColumnCount = 21

    Debug.Assert dfSlice.getDataByColName(0, "colX") = ""
    Debug.Assert dfSlice.getDataByColName(1, "colX") = ""

    Debug.Assert df.getDataByColName(0, "colX") = ""
    Debug.Assert df.getDataByColName(1, "colX") = ""
End Sub

' 测试: 获取指定行的描述器
Private Sub test_getRowDescriptor()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4)
    colIndexes = Array(1, 3)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 获取指定行的描述器
    Dim d As IDFDescriptor
    Set d = df.getRowDescriptor(5, True)

    Dim d2 As IDFDescriptor
    Set d2 = dfSlice.getRowDescriptor(0, True)

    Debug.Assert d2 Is d
End Sub

' 测试: 获取指定行列确定的槽位的描述器
Private Sub test_getDataDescriptor()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4)
    colIndexes = Array(1, 3)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 获取指定行的描述器
    Dim d As IDFDescriptor
    Set d = df.getDataDescriptor(5, 1, True)

    Dim d2 As IDFDescriptor
    Set d2 = dfSlice.getDataDescriptor(0, 0, True)

    Debug.Assert d2 Is d
End Sub

' 测试: 读取数据
Private Sub test_getDataByColIndex()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4)
    colIndexes = Array(1, 3)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 读取数据，并比较
    Debug.Assert dfSlice.getDataByColIndex(0, 0) = df.getDataByColIndex(5, 1)
End Sub

' 测试: 读取数据
Private Sub test_getDataByColName()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4)
    colIndexes = Array(1, 3)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 读取数据，并比较
    Debug.Assert dfSlice.getDataByColName(0, "1") = df.getDataByColName(5, "1")
End Sub

' 测试: 写入数据
Private Sub test_setDataByColIndex()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4)
    colIndexes = Array(1, 3)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 写入数据，并比较
    Debug.Assert dfSlice.getDataByColIndex(0, 0) = "c51"
    Debug.Assert df.getDataByColIndex(5, 1) = "c51"

    dfSlice.setDataByColIndex 0, 0, "abc"

    Debug.Assert dfSlice.getDataByColIndex(0, 0) = "abc"
    Debug.Assert df.getDataByColIndex(5, 1) = "abc"
End Sub

' 测试: 写入数据
Private Sub test_setDataByColName()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4)
    colIndexes = Array(1, 3)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 写入数据，并比较
    Debug.Assert dfSlice.getDataByColIndex(0, 0) = "c51"
    Debug.Assert df.getDataByColIndex(5, 1) = "c51"

    dfSlice.setDataByColName 0, "1", "abc"

    Debug.Assert dfSlice.getDataByColIndex(0, 0) = "abc"
    Debug.Assert df.getDataByColIndex(5, 1) = "abc"
End Sub

' 测试: 创建多级切片
Private Sub test_slice()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 创建第一级切片
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4, 3, 2, 1)
    colIndexes = Array(1, 3, 5, 7)

    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 3. 创建第二级切片
    Dim rowIndexes02() As Variant
    Dim colIndexes02() As Variant
    rowIndexes02 = Array(2, 3)
    colIndexes02 = Array(1, 2)

    Dim dfSlice02 As IDataFrame
    Set dfSlice02 = dfSlice.slice(rowIndexes:=rowIndexes02, colIndexes:=colIndexes02)

    ' 4. 检查结果
    Debug.Assert dfSlice02.getDataByColIndex(0, 0) = dfSlice.getDataByColIndex(2, 1)
    Debug.Assert dfSlice02.getDataByColIndex(0, 0) = df.getDataByColIndex(3, 3)
End Sub

' 测试: 将 DataFrame 中的内容输出到控制台
'       无法断言，只能手动检查
Private Sub test_printToConsole()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4)
    colIndexes = Array(1, 3)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 输出数据
    dfSlice.printToConsole True
End Sub

' 测试: 将 DataFrame 中的内容输出到指定 sheet 中
'       无法断言，只能手动检查
Private Sub test_printToWorksheet()
    ' 1. 创建一个 20 * 20 的数据表，表内的数据为: c<行索引><列索引>
    Dim df As IDataFrame
    Set df = getStringDF(20, 20)

    ' 2. 设置切片后需要的行列索引数组(索引从 0 开始)
    Dim rowIndexes() As Variant
    Dim colIndexes() As Variant
    rowIndexes = Array(5, 4)
    colIndexes = Array(1, 3)

    ' 3. 创建切片
    Dim dfSlice As IDataFrame
    Set dfSlice = df.slice(rowIndexes:=rowIndexes, colIndexes:=colIndexes)

    ' 4. 输出数据
    dfSlice.printToWorksheet ActiveSheet
End Sub
